package com.youtellv1.service.Impl;

import com.github.pagehelper.PageInfo;
import com.youtellv1.entity.Teachers;
import com.youtellv1.mapper.TeachersMapper;
import com.youtellv1.service.TeachersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeachersServiceImpl implements TeachersService {
    @Resource
    private TeachersMapper teachersMapper;

    @Override
    public PageInfo<Teachers> findTeachersByPage(int page, int size) {
        int offset = (page - 1) * size;
        List<Teachers> list = teachersMapper.findAllTeachers(offset, size);

        int total = teachersMapper.teachersCount();

        PageInfo<Teachers> pageInfo = new PageInfo<>(list);
        pageInfo.setTotal(total);
        pageInfo.setPageNum(page);
        pageInfo.setPageSize(size);

        return pageInfo;
    }

    @Override
    public Teachers findAllService(Teachers teachers) {
        return teachersMapper.findTeachersById(teachers);
    }

    @Override
    public Teachers findTeaById(Integer tid) {
        return teachersMapper.findTeaById(tid);
    }

    @Override
    public void saveService(Teachers teachers) {
        teachersMapper.save(teachers);
    }

    @Override
    public void updateFlagService(Integer tid, Integer flag) {
        teachersMapper.updateFlag(tid, flag);
    }

    @Override
    public void updateService(Teachers teachers) {
        teachersMapper.update(teachers);
    }

    @Override
    public void deleteService(Teachers teachers) {
        teachersMapper.delete(teachers);
    }

    @Override
    public Integer teachersCountService() {
        return teachersMapper.teachersCount();
    }

    @Override
    public Teachers findNameByTid(Integer tid) {
        return teachersMapper.findNameByTid(tid);
    }

    @Override
    public Teachers findById(Integer id) {
        return teachersMapper.findById(id);
    }

}
